let s = "leetcode";
let wordDict = ["leet", "code"];
let result = [];


function backtrack(start, path, remainStr, remainCount) {
  if (remainCount < 0) {
    return;
  } else if (remainCount == 0) {
    result.push([...path]);
    return;
  }
  for (let i = start; i < wordDict.length; i++) {
    path.push(wordDict[i]);
    backtrack(
      i,
      path,
      remainStr.replace(wordDict[i], ""),
      remainStr.length - wordDict[i].length
    );
    path.pop();
  }
}
backtrack(0, [], s, s.length);

console.log(result);

